import json
demo_node_str = """MERGE ({var_name}: {tag_name}{property_str})"""
demo_relation_str = """MERGE ({var1})-[:{tag_name} {property_str}]->({var2})"""


def make_property_str(info_dict):
    property_str = ""
    if info_dict:
        key_value_list = ["%s:\"%s\"" % (key, value) for key, value in info_dict.items()]
        key_value_str = ",".join(key_value_list)
        property_str = "{" + key_value_str + "}"
    return property_str

def create_neo4j_node_merge_string(tag_name,var_name,info_dict=None):
    property_str = ""
    if info_dict:
        property_str = make_property_str(info_dict)

    neo4j_str = demo_node_str.format(var_name=var_name,tag_name=tag_name,property_str=property_str)
    return neo4j_str

def create_neo4j_relation_merge_string(p,q,relation_tag,relation_property=None):
    property_str = ""
    if relation_property:
        property_str = make_property_str(relation_property)

    neo4j_str = demo_relation_str.format(var1=p, var2=q, tag_name=relation_tag,property_str=property_str)
    return neo4j_str


if __name__ == '__main__':
    demo_dict ={"name":"呵呵"}
    create_neo4j_node_merge_string(info_dict=demo_dict,tag_name='a',var_name="1")